package concurrent;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;
import java.util.concurrent.TimeUnit;

public class CallableDemo implements Callable<String> {
    @Override
    public String call() throws InterruptedException {
        TimeUnit.SECONDS.sleep(1);
        return "Callable Demo";
    }

    public static void main(String[] args) {
        FutureTask<String> futureTask = new FutureTask<>(new CallableDemo());
        new Thread(futureTask).start();

        try {
            String s = futureTask.get();
            System.out.println("s = " + s);
        } catch (InterruptedException | ExecutionException e) {
            throw new RuntimeException(e);
        }
    }
}
